<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%exhibition}}".
 *
 * @property integer $id
 * @property integer $category_id
 * @property string $title
 * @property integer $hall_id
 * @property string $hall_title
 * @property string $logo
 * @property string $litpic
 * @property string $bg
 * @property integer $starttime
 * @property integer $endtime
 * @property string $address
 * @property string $city
 * @property string $area
 * @property integer $hot
 * @property string $wechat_qrcode
 * @property string $introduce
 * @property string $video
 * @property string $scope
 * @property string $booth_info
 * @property string $website
 * @property integer $recommend
 * @property integer $audience_number
 * @property integer $comments_number
 * @property integer $score
 * @property integer $business_number
 * @property integer $follow_number
 * @property integer $build_number
 * @property integer $views_num
 * @property string $tags
 * @property string $sponsor
 * @property string $undertook
 * @property integer $status
 * @property integer $order
 * @property integer $version
 * @property string $created_by
 * @property integer $created_at
 * @property string $created_from
 * @property string $created_ip
 * @property string $updated_by
 * @property integer $updated_at
 * @property string $updated_from
 * @property string $updated_ip
 * @property integer $is_deleted
 *
 * @property ExhibitionComments[] $exhibitionComments
 */
class Exhibition extends \common\base\BaseActiveRecord
{

    //热门度
    const HOT_ZERO = '0';
    const HOT_ONE = '1';
    const HOT_TWO = '2';
    const HOT_THREE = '3';
    const HOT_FOUR = '4';
    const HOT_FIVE = '5';

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%exhibition}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'category_id', 'hall_id', 'starttime', 'endtime', 'area', 'hot', 'address', 'audience_number', 'business_number','website', 'build_number', 'introduce', 'scope', 'booth_info'], 'required'],
            [['category_id', 'hall_id', 'hot', 'recommend', 'audience_number', 'comments_number', 'business_number', 'follow_number', 'build_number', 'views_num', 'status', 'order', 'version', 'created_at', 'updated_at', 'is_deleted'], 'integer'],
            [['score'], 'number'],
            [['introduce', 'scope', 'booth_info', 'sponsor', 'undertook'], 'string'],
            [['title', 'address', 'video'], 'string', 'max' => 255],
            [['hall_title', 'city'], 'string', 'max' => 100],
            [['litpic', 'logo', 'bg'], 'string', 'max' => 200],
            [['area'], 'string', 'max' => 30],
            [['tags'], 'string', 'max' => 50],
            [['wechat_qrcode'], 'string', 'max' => 500],
            [['website'], 'string', 'max' => 150],
            ['website', 'url', 'defaultScheme' => 'http'],
            //['endtime', 'compare', 'compareValue' => 'starttime', 'operator' => '>', 'message' => Yii::t('common','endtime_lt_starttime')],
            [['created_by', 'created_from', 'created_ip', 'updated_by', 'updated_from', 'updated_ip'], 'string', 'max' => 50],
            [['follow_number', 'comments_number', 'views_num', 'order'], 'default', 'value' => 0],
            ['score', 'default', 'value' => 5],
            ['status', 'default', 'value' => self::STATUS_FLAG_NORMAL],
            ['status', 'in', 'range' => [self::STATUS_FLAG_TEMP, self::STATUS_FLAG_NORMAL, self::STATUS_FLAG_STOP]],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'id'),
            'category_id' => Yii::t('common', 'category_id'),
            'title' => Yii::t('common', 'title'),
            'hall_id' => Yii::t('common', 'exhibition_hall'),
            'hall_title' => Yii::t('common', 'hall_name'),
            'logo' => Yii::t('common', 'exhibition_logo'),
            'litpic' => Yii::t('common', 'litpic'),
            'bg' => Yii::t('common', 'bg'),
            'starttime' => Yii::t('common', 'starttime'),
            'endtime' => Yii::t('common', 'endtime'),
            'address' => Yii::t('common', 'address'),
            'city' => Yii::t('common', 'city'),
            'area' => Yii::t('common', 'area'),
            'hot' => Yii::t('common', 'hot_rank'),
            'wechat_qrcode' => Yii::t('common', 'wechat_qrcode'),
            'introduce' => Yii::t('common', 'introduce'),
            'video' => Yii::t('common', 'video'),
            'scope' => Yii::t('common', 'scope'),
            'booth_info' => Yii::t('common', 'booth_info'),
            'website' => Yii::t('common', 'website'),
            'recommend' => Yii::t('common', 'recommend'),
            'audience_number' => Yii::t('common', 'audience_number'),
            'comments_number' => Yii::t('common', 'comments_number'),
            'score' => Yii::t('common', 'score'),
            'business_number' => Yii::t('common', 'business_number'),
            'follow_number' => Yii::t('common', 'follow_number'),
            'build_number' => Yii::t('common', 'build_number'),
            'views_num' => Yii::t('common', 'views_num'),
            'tags' => Yii::t('common', 'tags'),
            'sponsor' => Yii::t('common', 'sponsor'),
            'undertook' => Yii::t('common', 'undertook'),
            'status' => Yii::t('common', 'status'),
            'order' => Yii::t('common', 'order'),
            'version' => Yii::t('common', 'version'),
            'created_by' => Yii::t('common', 'created_by'),
            'created_at' => Yii::t('common', 'created_at'),
            'created_from' => Yii::t('common', 'created_from'),
            'created_ip' => Yii::t('common', 'created_ip'),
            'updated_by' => Yii::t('common', 'updated_by'),
            'updated_at' => Yii::t('common', 'updated_at'),
            'updated_from' => Yii::t('common', 'updated_from'),
            'updated_ip' => Yii::t('common', 'updated_ip'),
            'is_deleted' => Yii::t('common', 'is_deleted'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getExhibitionComments()
    {
        return $this->hasMany(ExhibitionComments::className(), ['exhibition_id' => 'id']);
    }
}
